<template>
	<view>
		<view class="form">
			<view class="form_item">
				<view class="title" style="color:#999999">为有效保障您的资金安全，提升订单处理效率，请填写与您身份证一致的信息，否则不会通过审核。</view>
			</view>
			
			<view class="form_item">
				<view class="title">姓名</view>
				<view style="display: flex;align-items: center;">
				    <input placeholder="请输入姓名" v-model="realName" style="text-align: right;" />
				</view>
			</view>
			
			<view class="form_item">
				<view class="title">身份证号</view>
				<view style="display: flex;align-items: center;">
				<input placeholder="请输入身份证号" v-model="cardNo" style="text-align: right;" />
				</view>
			</view>
			
			<view class="btn" @tap="updateidcard">
				提交认证
			</view>
	  </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				realName:'',
				cardNo:''
			}
		},
		methods: {
			updateidcard(){
				let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
				if(reg.test(this.cardNo) === false) { 
							uni.showToast({
								title: '身份证号码不正确',
								duration: 1000,
								icon: "none"
							});
					return
				}
				if(this.realName == ''){
					uni.showToast({
						title: '请填写姓名',
						duration: 1000,
						icon: "none"
					});
					return
				}
				this.$api.updateidcard({
					realName:this.realName,
					cardNo:this.cardNo,
				}).then((res) => {
					if(res.data.code==200){
						uni.showToast({
							title: '认证完成',
							duration: 1000,
							icon: 'none'
						})
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							});
						}, 1000);
					}else{
						uni.showToast({
							title: res.data.message,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>
<style lang="scss">
.uni-radio-wrapper{transform: scale(0.7);}
.form{background-color: white;margin-top:10px;}
  .form_item{
	  border-bottom: 1px solid #EEEEEE;
	  padding:10px;
	  display: flex;
	  justify-content: space-between;
	  align-items:center;
	  .title{font-weight: bold;color:#333333}
  }
  
  .btn{
     background-color: #FF5533;
     border-radius:50px;
     padding: 10px;
     width: 80%;
     font-size: 28rpx;
     margin: 50px auto;
     color:white;text-align: center;
    }
</style>